package com.rui.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rui.reggie.common.BaseContext;
import com.rui.reggie.entity.ShoppingCart;
import com.rui.reggie.mapper.ShoppingCartMapper;
import com.rui.reggie.service.ShoppingCartService;
import org.springframework.stereotype.Service;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : ShoppingCartServiceImpl
 * @createTime : [2022/5/25 13:27]
 * @description : [描述该类的功能]
 */

@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {

    /**
     * 清空购物车
     */
    @Override
    public void clean() {
        //SQL: delete from shopping_cart where user_id = ?
        LambdaQueryWrapper<ShoppingCart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShoppingCart::getUserId, BaseContext.getCurrentId());
        this.remove(queryWrapper);
    }
}
